<?php

/* ------------------------------------------------
	Theme Setup
------------------------------------------------ */

if ( ! isset( $content_width ) ) $content_width = 640;

add_action( 'after_setup_theme', 'qns_setup' );

if ( ! function_exists( 'qns_setup' ) ):

function qns_setup() {

	add_theme_support( 'post-thumbnails' );
	
	if ( function_exists( 'add_theme_support' ) ) {
		add_theme_support( 'post-thumbnails' );
	        set_post_thumbnail_size( "100", "100" );  
	}

	if ( function_exists( 'add_image_size' ) ) {
		add_image_size( 'image-style1', 680, 450, true );
		add_image_size( 'image-style2', 124, 101, true );
		add_image_size( 'image-style3', 95, 76, true );
		add_image_size( 'image-style4', 330, 220, true );
		add_image_size( 'image-style5', 73, 52, true );
		add_image_size( 'shop-thumb', 92, 126, true );
		add_image_size( 'gallery-thumb-large', 500, 500, true );
	}
	
	add_theme_support( 'automatic-feed-links' );
	
	load_theme_textdomain( 'qns', get_template_directory() . '/languages' );

	$locale = get_locale();
	$locale_file = get_template_directory() . "/languages/$locale.php";
	if ( is_readable( $locale_file ) ) require_once( $locale_file );

	register_nav_menus( array(
		'primary' => __( 'Primary Navigation', 'qns' ),
	) );

}
endif;



/* ------------------------------------------------
	Comments Template
------------------------------------------------ */

if( ! function_exists( 'qns_comments' ) ) {
	function qns_comments($comment, $args, $depth) {
	   $path = get_template_directory_uri();
	   $GLOBALS['comment'] = $comment;
	   ?>
		
	<li <?php comment_class('comment-entry clearfix'); ?> id="comment-<?php comment_ID(); ?>">

		<!-- BEGIN .comment-left -->
		<div class="comment-left">
			<div class="comment-image">
				<?php echo get_avatar( $comment, 60 ); ?>
			</div>
		<!-- END .comment-left -->
		</div>

		<!-- BEGIN .comment-right -->
		<div class="comment-right">
					
			<?php if ( $comment->comment_approved == '0' ) : ?>
				<div class="msg success clearfix"><p><?php _e( 'Your comment is awaiting moderation.', 'qns' ); ?></p></div>
			<?php endif; ?>
					
			<p class="comment-info"><?php printf( __( '%s', 'qns' ), sprintf( '%s', get_comment_author_link() ) ); ?> 
				<span><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
				<?php printf( __( '%1$s at %2$s', 'qns' ), get_comment_date(),  get_comment_time() ); ?>
				</a></span>
			</p>
					
			<div class="comment-text">
				<?php comment_text(); ?>
			</div>
					
			<p><span class="reply">
				<?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
				<?php edit_comment_link( __( '(Edit)', 'qns' ), ' ' ); ?>
			</span></p>

		<!-- END .comment-right -->
		</div>		

	<?php }
}



/* ------------------------------------------------
   Options Panel
------------------------------------------------ */

require_once ('admin/index.php');



/* ------------------------------------------------
	Register Sidebars
------------------------------------------------ */

function qns_widgets_init() {

	// Area 1, located at the top of the sidebar.
	register_sidebar( array(
		'name' => __( 'Primary Widget Area', 'qns' ),
		'id' => 'primary-widget-area',
		'description' => __( 'The primary widget area', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h3>',
		'after_title' => '</h3><div class="widget-title-border"><div class="widget-title-block"></div></div></div>',
	) );
	
	// Area 2, located in the footer. Empty by default.
	register_sidebar( array(
		'name' => __( 'Footer Widget Area One', 'qns' ),
		'id' => 'footer-widget-area-one',
		'description' => __( 'Footer widget area one', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h6>',
		'after_title' => '</h6></div>',
	) );
	
	// Area 3, located in the footer. Empty by default.
	register_sidebar( array(
		'name' => __( 'Footer Widget Area Two', 'qns' ),
		'id' => 'footer-widget-area-two',
		'description' => __( 'Footer widget area two', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h6>',
		'after_title' => '</h6></div>',
	) );
	
	// Area 4, located in the footer. Empty by default.
	register_sidebar( array(
		'name' => __( 'Footer Widget Area Three', 'qns' ),
		'id' => 'footer-widget-area-three',
		'description' => __( 'Footer widget area three', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h6>',
		'after_title' => '</h6></div>',
	) );
	
	// Area 5, located in the footer. Empty by default.
	register_sidebar( array(
		'name' => __( 'Footer Widget Area Four', 'qns' ),
		'id' => 'footer-widget-area-four',
		'description' => __( 'Footer widget area four', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h6>',
		'after_title' => '</h6></div>',
	) );
	
	// Area 6, located only on WooCommerce pages. Empty by default.
	register_sidebar( array(
		'name' => __( 'WooCommerce Widget Area', 'qns' ),
		'id' => 'woocommerce-widget-area',
		'description' => __( 'Widgets in this area will only be displayed on WooCommerce store pages', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h3>',
		'after_title' => '</h3><div class="widget-title-border"><div class="widget-title-block"></div></div></div>',
	) );
        
        register_sidebar( array(
		'name' => __( 'Common Sidebar', 'qns' ),
		'id' => 'common-sidebar',
		'description' => __( 'Common Sidebar', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h3>',
		'after_title' => '</h3><div class="widget-title-border"><div class="widget-title-block"></div></div></div>',
	) );
        
        register_sidebar( array(
		'name' => __( 'Home Sidebar', 'qns' ),
		'id' => 'home-sidebar',
		'description' => __( 'Widgets in this area will only be displayed on home page', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h3>',
		'after_title' => '</h3><div class="widget-title-border"><div class="widget-title-block"></div></div></div>',
	) );
        
        register_sidebar( array(
		'name' => __( 'Novias Sidebar', 'qns' ),
		'id' => 'novias-sidebar',
		'description' => __( 'Widgets in this area will only be displayed on Novias page', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h3>',
		'after_title' => '</h3><div class="widget-title-border"><div class="widget-title-block"></div></div></div>',

	) );
        
        register_sidebar( array(
		'name' => __( 'Horarios Sidebar', 'qns' ),
		'id' => 'horarios-sidebar',
		'description' => __( 'Widgets in this area will only be displayed on Horarios page', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h3>',
		'after_title' => '</h3><div class="widget-title-border"><div class="widget-title-block"></div></div></div>',

	) );
        
        register_sidebar( array(
		'name' => __( 'Ventas Corporativas', 'qns' ),
		'id' => 'ventascorporativas-sidebar',
		'description' => __( 'Widgets in this area will only be displayed on Ventas Corporativas page', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h3>',
		'after_title' => '</h3><div class="widget-title-border"><div class="widget-title-block"></div></div></div>',
	) );
        
        register_sidebar( array(
		'name' => __( 'Blog Sidebar', 'qns' ),
		'id' => 'blog-sidebar',
		'description' => __( 'Widgets in this area will only be displayed on blog page', 'qns' ),
		'before_widget' => '<div class="widget">',
		'after_widget' => '</div>',
		'before_title' => '<div class="widget-title clearfix"><h3>',
		'after_title' => '</h3><div class="widget-title-border"><div class="widget-title-block"></div></div></div>',
	) );

}

add_action( 'widgets_init', 'qns_widgets_init' );



/* ------------------------------------------------
	Register Menu
------------------------------------------------ */

if( !function_exists( 'qns_register_menu' ) ) {
	function qns_register_menu() {

		register_nav_menus(
		    array(
				'primary' => __( 'Primary Navigation','qns' ),
				'secondary' => __( 'Secondary Navigation','qns' ),
				'footer' => __( 'Footer Navigation','qns' )
		    )
		  );
		
	}

	add_action('init', 'qns_register_menu');
}



/* ------------------------------------------------
	Add Description Field to Menu
------------------------------------------------ */

class description_walker extends Walker_Nav_Menu
{
      function start_el(&$output, $item, $depth, $args)
      {
           global $wp_query;
           $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

           $class_names = $value = '';

           $classes = empty( $item->classes ) ? array() : (array) $item->classes;

           $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
           $class_names = ' class="'. esc_attr( $class_names ) . '"';

           $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';

           $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
           $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
           $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
           $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';

           $prepend = '<strong>';
           $append = '</strong>';
           $description  = ! empty( $item->description ) ? '<span>'.esc_attr( $item->description ).'</span>' : '';

           if($depth != 0) {
				$description = $append = $prepend = "";
           }

            $item_output = $args->before;
            $item_output .= '<a'. $attributes .'>';
            $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
            $item_output .= $description.$args->link_after;
            $item_output .= '</a>';
            $item_output .= $args->after;

            $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
		}
}



/* ------------------------------------------------
	Get Post Type
------------------------------------------------ */

function is_post_type($type){
    global $wp_query;
    if($type == get_post_type($wp_query->post->ID)) return true;
    return false;
}



/* ------------------------------------------------
   Register Dependant Javascript Files
------------------------------------------------ */

add_action('wp_enqueue_scripts', 'qns_load_js');

if( ! function_exists( 'qns_load_js' ) ) {
	function qns_load_js() {

		if ( is_admin() ) {
			
		}
		
		else {
			
			// Load JS		
			wp_register_script( 'jquery_ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js', array( 'jquery' ), '1.8', true );
			wp_register_script( 'hoverintent', get_template_directory_uri() . '/js/hoverIntent.js', array( 'jquery' ), '1.4.8', true );
			wp_register_script( 'superfish', get_template_directory_uri() . '/js/superfish.js', array( 'jquery' ), '1.4.8', true );
			wp_register_script( 'prettyphoto', get_template_directory_uri() . '/js/jquery.prettyPhoto.js', array( 'jquery' ), '1.1.9', true );
			wp_register_script( 'flexslider', get_template_directory_uri() . '/js/jquery.flexslider-min.js', array( 'jquery' ), '1.1.9', true );
			wp_register_script( 'selectivizr', get_template_directory_uri() . '/js/selectivizr-min.js', array( 'jquery' ), '1.0.2', true );
			wp_register_script( 'custom', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ), '1', true );

			wp_enqueue_script( array( 'jquery_ui', 'hoverintent', 'superfish', 'prettyphoto', 'flexslider', 'custom' ) );
			
			global $is_IE;
			
			if( $is_IE ) wp_enqueue_script( 'selectivizr' );
			if( is_single() ) wp_enqueue_script( 'comment-reply' );
			
			// Load CSS
			wp_enqueue_style('superfish', get_template_directory_uri() .'/css/superfish.css');
			wp_enqueue_style('prettyPhoto', get_template_directory_uri() .'/css/prettyPhoto.css');
			wp_enqueue_style('flexslider', get_template_directory_uri() .'/css/flexslider.css');
			wp_enqueue_style('responsive', get_template_directory_uri() .'/css/responsive.css');

			
		}
	}
}

if( !function_exists( 'custom_js' ) ) {

    function custom_js() {
		
		global $data; //fetch options stored in $data
		
		echo '<script>';
		echo "\n";
		
		// Set slideshow autoplay on/off
		if ( $data['slideshow_autoplay'] ) :
			echo 'var slideshow_autoplay = true;';
			echo "\n";
		else :
			echo 'var slideshow_autoplay = false;';
			echo "\n";
		endif;
		
		// Set slideshow speed
		if ( $data['slideshow_speed'] ) :
			echo 'var slideshow_speed = ' . $data['slideshow_speed'] . ';';
			echo "\n";
		else :
			echo 'var slideshow_speed = 7000;';
			echo "\n";
		endif;
		
		// Check if slideshow contains video
		if ( $data['slideshow_video'] ) :
			echo 'var slideshow_video = true;';
			echo "\n";
		else :
			echo 'var slideshow_video = false;';
			echo "\n";
		endif;
		
		echo 'var goText = "' . __('Go to...','qns') . '";';
		echo "\n";
		
		// Set the checkout form placeholder text
		echo 'var checkoutFirstName = "' . __('First Name','qns') . '";';
		echo "\n";
		
		echo 'var checkoutLastName = "' . __('Last Name','qns') . '";';
		echo "\n";
		
		echo 'var checkoutCompanyName = "' . __('Company Name','qns') . '";';
		echo "\n";
		
		echo 'var checkoutTownCity = "' . __('Town / City','qns') . '";';
		echo "\n";
		
		echo 'var checkoutStateCounty = "' . __('State / County','qns') . '";';
		echo "\n";
		
		echo 'var checkoutPostcodeZip = "' . __('Postcode / Zip','qns') . '";';
		echo "\n";
		
		echo 'var checkoutEmailAddress = "' . __('Email Address','qns') . '";';
		echo "\n";
		
		echo 'var checkoutPhoneNumber = "' . __('Phone Number','qns') . '";';
		echo "\n";
		
		echo "</script>\n\n";
		
    }

}

add_action('wp_footer', 'custom_js');



/* ------------------------------------------------
   Load Files
------------------------------------------------ */

// Shortcodes
include 'functions/shortcodes/adverts.php';
include 'functions/shortcodes/accordion.php';
include 'functions/shortcodes/googlemap.php';
include 'functions/shortcodes/gallery.php';
include 'functions/shortcodes/toggle.php';
include 'functions/shortcodes/list.php';
include 'functions/shortcodes/button.php';
include 'functions/shortcodes/columns.php';
include 'functions/shortcodes/video.php';
include 'functions/shortcodes/title.php';
include 'functions/shortcodes/message.php';
include 'functions/shortcodes/dropcap.php';
include 'functions/shortcodes/tabs.php';


include 'functions/shortcodes/clear.php';


include 'functions/shortcodes/news-slides.php';
include 'functions/shortcodes/news-5-cols.php';
include 'functions/shortcodes/news-2-cols.php';
include 'functions/shortcodes/news-2-cols-slides.php';
include 'functions/shortcodes/shop.php';

include 'functions/shortcodes/novia.php';
include 'functions/shortcodes/horario.php';
include 'functions/shortcodes/googlemap_custom.php';

// Widgets
include 'functions/widgets/widget-adverts.php';
include 'functions/widgets/widget-flickr.php';
include 'functions/widgets/widget-tags.php';
include 'functions/widgets/widget-recent-posts.php';
include 'functions/widgets/widget-category-posts.php';
include 'functions/widgets/widget-social.php';



/* ------------------------------------------------
	Custom CSS
------------------------------------------------ */

function custom_css() {
	
	global $data; //fetch options stored in $data
	
	// Set Font Family
	if ( !$data['custom_font'] ) { 
		$custom_font = "'Cardo', serif"; } 
	else { 
		$custom_font =  $data['custom_font']; 
	}
	
	// Output Custom CSS
	$output = '<style type="text/css">
	
		h1, h2, h3, h4, h5, h6, 
		.cart-top, 
		.flex-caption h2, 
		.dropcap, 
		.page-content table th,
		#site-title #tagline,
		.news-image-title,
		blockquote,
		.product-price .from,
		.product-price-single .from {
		font-family: ' . $custom_font . ';
	}
	
	' . $data['custom_css'];
	
	if ( $data['body_background'] and $data['body_background_image'] ) {
		
		if ( $data['background_repeat'] ) {
			$background_repeat = $data['background_repeat'];
		}
		else {
			$background_repeat = 'repeat';
		}
		
		$output .= 'body {
			background: url(' . $data['body_background_image'] . ') ' . $data['body_background'] . ' fixed ' . $data['background_repeat'] . ' !important;
		}';
	}
	
	elseif ( $data['body_background'] ) { 
		$output .= 'body {
			background: ' . $data['body_background'] . ' !important;
		}';
	}
	
	elseif ( $data['body_background_image'] ) { 
		$output .= 'body {
			background: url(' . $data['body_background_image'] . ') fixed ' . $data['background_repeat'] . ' !important;
		}';
	}
	
	if ( $data['mobile_search_bg'] ) { 
		$output .= '@media only screen and (max-width: 1100px) {
			.menu-search-field {
				background: ' . $data['mobile_search_bg'] . ' !important;
			}
		}';
	}
	
	if ( $data['mobile_search_text'] ) { 
		$output .= '@media only screen and (max-width: 1100px) {
			.menu-search-field {
				color: ' . $data['mobile_search_text'] . ' !important;
			}
		}';
	}
	
	if ( $data['main_color'] ) { 
		
		$output .= '@media only screen and (max-width: 1100px) {
		
			#main-menu-wrapper {
				background: ' . $data['main_color'] . ' !important;
				border-top: ' . $data['main_color'] . ' 1px solid !important;
				border-bottom: ' . $data['main_color'] . ' 1px solid !important;
			}
		
		}';
		
		$output .= '#site-title h2 { border-top: 6px solid ' . $data['main_color'] . '; }';
		
		$output .= '.twitter_icon:hover,.pinterest_icon:hover,.facebook_icon:hover,.googleplus_icon:hover,.tumblr_icon:hover,
		.vimeo_icon:hover,.youtube_icon:hover,.rss_icon:hover,.flickr_icon:hover { background-color: ' . $data['main_color'] . '; }';
		
		$output .= '.menu-search-button { background-color: ' . $data['main_color'] . '; }';
		
		$output .= '.slider .flex-direction-nav .flex-prev { border-right: ' . $data['main_color'] . ' 4px solid; }';

		$output .= '.slider .flex-direction-nav .flex-next { border-left: ' . $data['main_color'] . ' 4px solid; }';
		
		$output .= '.widget-title-block { background: ' . $data['main_color'] . ';}';
		
		$output .= '.nsu-submit { background-color: ' . $data['main_color'] . ';}';
		
		$output .= '.news-image-title { background: ' . $data['main_color'] . ';}';
		
		$output .= '.title-block, #reply-title { background: ' . $data['main_color'] . ';}';
		
		$output .= '#footer-bottom { background: ' . $data['main_color'] . ';}';
		
		$output .= '.price_slider_wrapper .ui-slider .ui-slider-handle { background: ' . $data['main_color'] . ';}';
		
		$output .= '#main-menu li ul { border-bottom: ' . $data['main_color'] . ' 4px solid; }';

		$output .= '#minus1, #plus1 { background: ' . $data['main_color'] . ';}';
		
		$output .= '.add-to-bag { background: ' . $data['main_color'] . ';}';
		
		$output .= '.page-content table, #sidebar-content table, #footer-wrapper table { border-top: 5px solid ' . $data['main_color'] . ';}';
		
		$output .= '.product-options .product_type_simple,.product-options .product_type_external,
		.product-options .product_type_variable,.product-options .details-button { background-color: ' . $data['main_color'] . ';}';
		
		$output .= '.pagination-wrapper a.selected, .pagination-wrapper a:hover, .wp-pagenavi .current, .wp-pagenavi a:hover { background: ' . $data['main_color'] . ' !important;border: ' . $data['main_color'] . ' 1px solid !important;}';
		
		$output .= '.product-price .amount, .single_variation .price .amount, .product-price-single .amount { background: ' . $data['main_color'] . ';}';
		
		$output .= '.ui-tabs .ui-tabs-nav li.ui-tabs-selected { border-top: ' . $data['main_color'] . ' 5px solid;}';
		
		$output .= '@media only screen and (max-width: 1100px) {
			#main-menu-wrapper { background: ' . $data['main_color'] . ';border-top: ' . $data['main_color'] . ' 1px solid;border-bottom: ' . $data['main_color'] . ' 1px solid;}
		}';
		
		$output .= '#mobile-menu li { border-top: #fff 1px solid;}';
		
		$output .= '.mobile-menu-button { background-color: ' . $data['main_color'] . ';}';
		
		$output .= '.mobile-menu-wrapper { background: ' . $data['main_color'] . ';}';
		
		$output .= '#mobile-menu li a, #mobile-menu li.current_page_item ul li a {color:#fff;}';

	}
	
	if ( $data['main_text_color'] ) { 
		
		$output .= '#site-title a { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '.page-title, .page-title a { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '.widget-title h3 { color: ' . $data['main_text_color'] . ';}';
		
		$output .= 'h1, h2, h3, h4, h5, h6 { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '#footer-wrapper h6 { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '.widget .latest-posts-list li a { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '.article-category-col-2 li h3 a, .article-category-col-1 li h3 a { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '.news-title-lower a { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '.flex-caption h2 a { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '.news-title a { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '.shop-block-list li h4 a { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '.product-meta h3 a { color: ' . $data['main_text_color'] . ';}';
		
		$output .= '#tabs .nav li a { color: ' . $data['main_text_color'] . ';}';
		
	}
	
	if ( $data['main_text_hover_color'] ) { 
		
		$output .= '#main-content a:hover,#sidebar-content a:hover { color: ' . $data['main_text_hover_color'] . ';}';
		
	}
	
	if ( $data['shop_highlight'] ) { 
		
		$output .= '.product-options .product_type_simple:hover,
		.product-options .product_type_external:hover,
		.product-options .product_type_variable:hover,
		.product-options .details-button:hover { background-color: ' . $data['shop_highlight'] . '}';
		
		$output .= '.product-price ins .amount, .single_variation .price ins .amount, .product-price-single ins .amount { background: ' . $data['shop_highlight'] . ';}';
		
	}
	
	//$output .= '.single_variation .price, .product-price .from,.product-price-single .from {display: none;}';
	$output .= '.checkout-columns label {display:none !important;}';
	$output .= '.from, .single_variation .price, .single_variation .out-of-stock {display: none;}';
	
	$output .= '</style>';
	
	return $output;
	
}

function admin_style() {
	wp_enqueue_style('admin-css', get_template_directory_uri().'/css/admin.css');
}



/* -------------------------------------------------------
	Remove width / height attributes from gallery images
------------------------------------------------------- */

add_filter('wp_get_attachment_link', 'remove_img_width_height', 10, 1);
add_filter('wp_get_attachment_image_attributes', 'remove_img_width_height', 10, 1);

function remove_img_width_height($html) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}



/* ------------------------------------------------
	Remove rel attribute from the category list
------------------------------------------------ */

function remove_category_list_rel($output)
{
  $output = str_replace(' rel="category"', '', $output);
  return $output;
}
add_filter('wp_list_categories', 'remove_category_list_rel');
add_filter('the_category', 'remove_category_list_rel');



/* -----------------------------------------------------
	Remove <p> / <br> tags from nested shortcode tags
----------------------------------------------------- */

add_filter('the_content', 'shortcode_fix');
function shortcode_fix($content)
{   
    $array = array (
        '<p>[' => '[', 
        ']</p>' => ']', 
        ']<br />' => ']'
    );

    $content = strtr($content, $array);

	return $content;
}



/* ------------------------------------------------
	Excerpt Length
------------------------------------------------ */

function print_excerpt($length) {
	global $post;
	$text = $post->post_excerpt;
	if ( '' == $text ) {
		$text = get_the_content('');
		$text = apply_filters('the_content', $text);
		$text = str_replace(']]>', ']]>', $text);
	}
	$text = strip_shortcodes($text); 
	$text = strip_tags($text);

	$text = substr($text,0,$length);
	$excerpt = reverse_strrchr($text, '.', 1);
	if( $excerpt ) {
		echo apply_filters('the_excerpt',$excerpt);
	} else {
		echo apply_filters('the_excerpt',$text);
	}
}

function reverse_strrchr($haystack, $needle, $trail) {
    return strrpos($haystack, $needle) ? substr($haystack, 0, strrpos($haystack, $needle) + $trail) : false;
}



/* ------------------------------------------------
	Excerpt More Link
------------------------------------------------ */

function qns_continue_reading_link() {
		return '';
}

function qns_auto_excerpt_more( $more ) {
	return qns_continue_reading_link();
}
add_filter( 'excerpt_more', 'qns_auto_excerpt_more' );



/* ------------------------------------------------
	The Title
------------------------------------------------ */

function qns_filter_wp_title( $title, $separator ) {
	
	if ( is_feed() )
		return $title;

	global $paged, $page;

	if ( is_search() ) {
		$title = sprintf( __( 'Search results for %s', 'qns' ), '"' . get_search_query() . '"' );
		if ( $paged >= 2 )
			$title .= " $separator " . sprintf( __( 'Page %s', 'qns' ), $paged );
		$title .= " $separator " . home_url( 'name', 'display' );
		return $title;
	}

	$title .= get_bloginfo( 'name', 'display' );

	$site_description = get_bloginfo( 'description', 'display' );
	if ( $site_description && ( is_home() || is_front_page() ) )
		$title .= " $separator " . $site_description;

	if ( $paged >= 2 || $page >= 2 )
		$title .= " $separator " . sprintf( __( 'Page %s', 'qns' ), max( $paged, $page ) );

	return $title;
}
add_filter( 'wp_title', 'qns_filter_wp_title', 10, 2 );



/* ------------------------------------------------
	Sidebar Position
------------------------------------------------ */

function sidebar_position( $position ) {
	
	global $data; //fetch options stored in $data
	
	if ( $data['sidebar_position'] ) { 
		$sidebar = $data['sidebar_position']; 
	}

	else { 
		$sidebar = 'right';
	}
	
	if ( $sidebar == 'left' && $position == 'primary-content' ) {
		$output = 'id="main-content" class="main-content-left-sidebar"';
	}
	
	if ( $sidebar == 'right' && $position == 'primary-content' ) {
		$output = 'id="main-content"';
	}
	
	if ( $sidebar == 'left' && $position == 'secondary-content' ) {
		$output = 'id="sidebar-content" class="sidebar-content-left-sidebar"';
	}
	
	if ( $sidebar == 'right' && $position == 'secondary-content' ) {
		$output = 'id="sidebar-content"';
	}
	
	if ( $sidebar == 'none' && $position == 'primary-content' ) {
		$output = 'id="main-content" class="full-width"';
	}
	
	if ( $sidebar == 'none' && $position == 'secondary-content' ) {
		$output = 'full-width';
	}
	
	return $output;

}



/* ------------------------------------------------
	Main Menu Fallback
------------------------------------------------ */

function wp_page_menu_qns( $args = array() ) {
	$defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
	$args = wp_parse_args( $args, $defaults );
	$args = apply_filters( 'wp_page_menu_qns_args', $args );

	$menu = '';

	$list_args = $args;

	// Show Home in the menu
	if ( ! empty($args['show_home']) ) {
		if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
			$text = __('Home','qns');
		else
			$text = $args['show_home'];
		$class = '';
		if ( is_front_page() && !is_paged() )
			$class = 'class="current_page_item"';
		$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
		// If the front page is a page, add it to the exclude list
		if (get_option('show_on_front') == 'page') {
			if ( !empty( $list_args['exclude'] ) ) {
				$list_args['exclude'] .= ',';
			} else {
				$list_args['exclude'] = '';
			}
			$list_args['exclude'] .= get_option('page_on_front');
		}
	}

	$list_args['echo'] = false;
	$list_args['title_li'] = '';
	$menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );

	if ( $menu )
		$menu = '<ul id="main-menu" class="fl">' . $menu . '</ul>';

	$menu = $menu . "\n";
	$menu = apply_filters( 'wp_page_menu_qns', $menu, $args );
	if ( $args['echo'] )
		echo $menu;
	else
		return $menu;
}



/* ------------------------------------------------
	Mobile Menu Fallback
------------------------------------------------ */

function wp_page_mobile_menu_qns( $args = array() ) {
	$defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
	$args = wp_parse_args( $args, $defaults );
	$args = apply_filters( 'wp_page_mobile_menu_qns_args', $args );

	$menu = '';

	$list_args = $args;

	// Show Home in the menu
	if ( ! empty($args['show_home']) ) {
		if ( true === $args['show_home'] || '1' === $args['show_home'] || 1 === $args['show_home'] )
			$text = __('Home','qns');
		else
			$text = $args['show_home'];
		$class = '';
		if ( is_front_page() && !is_paged() )
			$class = 'class="current_page_item"';
		$menu .= '<li ' . $class . '><a href="' . home_url( '/' ) . '" title="' . esc_attr($text) . '">' . $args['link_before'] . $text . $args['link_after'] . '</a></li>';
		// If the front page is a page, add it to the exclude list
		if (get_option('show_on_front') == 'page') {
			if ( !empty( $list_args['exclude'] ) ) {
				$list_args['exclude'] .= ',';
			} else {
				$list_args['exclude'] = '';
			}
			$list_args['exclude'] .= get_option('page_on_front');
		}
	}

	$list_args['echo'] = false;
	$list_args['title_li'] = '';
	$menu .= str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages($list_args) );

	if ( $menu )
		$menu = '<ul id="mobile-menu" class="fl">' . $menu . '</ul>';

	$menu = $menu . "\n";
	$menu = apply_filters( 'wp_page_mobile_menu_qns', $menu, $args );
	if ( $args['echo'] )
		echo $menu;
	else
		return $menu;
}



/* ------------------------------------------------
	Password Protected Post Form
------------------------------------------------ */

add_filter( 'the_password_form', 'qns_password_form' );

function qns_password_form() {
	
	global $post;
	$label = 'pwbox-'.( empty( $post->ID ) ? rand() : $post->ID );
	$form = '<div class="msg fail clearfix"><p class="nopassword">' . __( 'This post is password protected. To view it please enter your password below', 'qns' ) . '</p></div>
<form class="protected-post-form" action="' . get_option('siteurl') . '/wp-login.php?action=postpass" method="post"><label for="' . $label . '">' . __( 'Password', 'qns' ) . ' </label><input name="post_password" id="' . $label . '" type="password" size="20" /><div class="clearboth"></div><input id="submit" type="submit" value="' . esc_attr__( "Submit" ) . '" name="submit"></form>';
	return $form;
	
}



/* ------------------------------------------------
	Google Fonts
------------------------------------------------ */

function google_fonts() {
	
	global $data; //fetch options stored in $data
	
	$output = '';
	
	if ( !$data['custom_font_code'] ) {
		$output .= "<link href='http://fonts.googleapis.com/css?family=Cardo:400,400italic,700' rel='stylesheet' type='text/css'>"; 
	}

	else { 
		$output .= $data['custom_font_code']; 
	}
	
	return $output;
	
}



/* ------------------------------------------------
	Page Header
------------------------------------------------ */

function page_header( $url ) {
	
	global $data; //fetch options stored in $data
	
	$header_url = '';
	
	// If custom page header is set
	if ( $url != '' ) {
		$header_url = $url;
	}
	
	// If default page header is set and custom header is not set
	if ( $data['default_header_url'] && $url == '' ) {
		$header_url = $data['default_header_url'];
	}
	
	$output = '<div id="page-header">';
	
	// If either of the above is set
	if ( $header_url != '' ) {
		$output .= '<img src="' . $header_url . '" alt="" />';
	}
	
	$output .= '</div>';
		
	return $output;
	
}



/* ------------------------------------------------
	Email Validation
------------------------------------------------ */

function valid_email($email) {
	
	$result = TRUE;
	
	if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
    	$result = FALSE;
	}
  	
	return $result;
	
}



/* ------------------------------------------------
	Add PrettyPhoto for Attached Images
------------------------------------------------ */

add_filter( 'wp_get_attachment_link', 'sant_prettyadd');
function sant_prettyadd ($content) {
     $content = preg_replace("/<a/","<a
rel=\"prettyPhoto[slides]\"",$content,1);
     return $content;
}



/* ------------------------------------------------
	Social Icons
------------------------------------------------ */

function no_icons() {
	
	global $data; //fetch options stored in $data
	
	if( $data['social_twitter'] ) { $twitter = $data['social_twitter']; }
	else { $twitter = ''; }
	
	if( $data['social_pinterest'] ) { $pinterest = $data['social_pinterest']; }
	else { $pinterest = ''; }
	
	if( $data['social_facebook'] ) { $facebook = $data['social_facebook']; }
	else { $facebook = ''; }

	if( $data['social_googleplus'] ) { $googleplus = $data['social_googleplus']; }
	else { $googleplus = ''; }

	if( $data['social_tumblr'] ) { $tumblr = $data['social_tumblr']; }
	else { $tumblr = ''; }
	
	if( $data['social_vimeo'] ) { $vimeo = $data['social_vimeo']; }
	else { $vimeo = ''; }
	
	if( $data['social_youtube'] ) { $youtube = $data['social_youtube']; }
	else { $youtube = ''; }
	
	if( $data['social_rss'] ) { $rss = $data['social_rss']; }
	else { $rss = ''; }

	if( $data['social_flickr'] ) { $flickr = $data['social_flickr']; }
	else { $flickr = ''; }
	
	if ( $twitter == ''  && $pinterest == '' && $facebook == '' && $googleplus == '' && $tumblr == '' && $vimeo == '' && $youtube == '' && $rss == '' && $flickr == '' ) {
		return true;
	}
}

function display_social() {
	
	global $data; //fetch options stored in $data
	
	if( $data['social_twitter'] ) { $twitter = $data['social_twitter']; }
	else { $twitter = ''; }
	
	if( $data['social_pinterest'] ) { $pinterest = $data['social_pinterest']; }
	else { $pinterest = ''; }
	
	if( $data['social_facebook'] ) { $facebook = $data['social_facebook']; }
	else { $facebook = ''; }

	if( $data['social_googleplus'] ) { $googleplus = $data['social_googleplus']; }
	else { $googleplus = ''; }

	if( $data['social_tumblr'] ) { $tumblr = $data['social_tumblr']; }
	else { $tumblr = ''; }
	
	if( $data['social_vimeo'] ) { $vimeo = $data['social_vimeo']; }
	else { $vimeo = ''; }
	
	if( $data['social_youtube'] ) { $youtube = $data['social_youtube']; }
	else { $youtube = ''; }
	
	if( $data['social_rss'] ) { $rss = $data['social_rss']; }
	else { $rss = ''; }

	if( $data['social_flickr'] ) { $flickr = $data['social_flickr']; }
	else { $flickr = ''; }
	
	$output = '';
	
	if ( no_icons() !== true ) {
		$output .= '<ul class="social-icons">';
	}	

        if( $pinterest !== '' ) {
		$output .= '<li><a href="' . $pinterest . '" target="_blank"><i class="fa fa-icon fa-pinterest"></i></a></li>';
	}
        
        if( $tumblr !== '' ) {
		$output .= '<li><a href="' . $tumblr . '" target="_blank"><i class="fa fa-icon fa-foursquare"></i></a></li>';
	}
        
        if( $youtube !== '' ) {
		$output .= '<li><a href="' . $youtube . '" target="_blank"><i class="fa fa-icon fa-youtube"></i></a></li>';
	}
        
	if( $twitter !== '' ) {
		$output .= '<li><a href="' . $twitter . '" target="_blank"><i class="fa fa-icon fa-twitter"></i></a></li>';
	}
	
	if( $facebook !== '' ) {
		$output .= '<li><a href="' . $facebook . '" target="_blank"><i class="fa fa-icon fa-facebook"></i></a></li>';
	}

	if( $googleplus !== '' ) {
		$output .= '<li><a href="' . $googleplus . '" target="_blank"><span class="googleplus_icon"></span></a></li>';
	}
	
	if( $vimeo !== '' ) {
		$output .= '<li><a href="' . $vimeo . '" target="_blank"><span class="vimeo_icon"></span></a></li>';
	}

	if( $rss !== '' ) {
		$output .= '<li><a href="' . $rss . '" target="_blank"><span class="rss_icon"></span></a></li>';
	}

	if( $flickr !== '' ) {
		$output .= '<li><a href="' . $flickr . '" target="_blank"><span class="flickr_icon"></span></a></li>';
	}

	if ( no_icons() !== true ) {
		$output .= '</ul>';
	}
	
	return $output;
	
}



/* ------------------------------------------------
	Breadcrumbs
------------------------------------------------ */

function dimox_breadcrumbs() {
 
  /* === OPTIONS === */
  $text['home']     = __('Home','qns'); // text for the 'Home' link
  $text['category'] = '%s'; // text for a category page
  $text['search']   = __('Search Results','qns'); // text for a search results page
  $text['tag']      = __('Posts Tagged "%s"','qns'); // text for a tag page
  $text['author']   = __('Articles Posted by %s','qns'); // text for an author page
  $text['404']      = __('Error 404','qns'); // text for the 404 page
 
  $showCurrent = 0; // 1 - show current post/page title in breadcrumbs, 0 - don't show
  $showOnHome  = 1; // 1 - show breadcrumbs on the homepage, 0 - don't show
  $delimiter   = '<li class="separator"><span>/</span></li>'; // delimiter between crumbs
  $before      = '<li><span class="current">'; // tag before the current crumb
  $after       = '</span></li>'; // tag after the current crumb
  /* === END OF OPTIONS === */
 
  global $post;
  $homeLink = home_url() . '/';
  $linkBefore = '<li><span>';
  $linkAfter = '</span></li>';
  $linkAttr = ' rel="v:url" property="v:title"';
  $link = $linkBefore . '<a' . $linkAttr . ' href="%1$s">%2$s</a>' . $linkAfter;
 
  if (is_home() || is_front_page()) {
 
    if ($showOnHome == 1) echo '<div class="breadcrumbs-wrapper clearfix"><ul class="breadcrumbs"><li><span><a href="' . $homeLink . '">' . $text['home'] . '</a></span></div>';
 
  } else {
 
    echo '<div class="breadcrumbs-wrapper clearfix"><ul class="breadcrumbs">' . sprintf($link, $homeLink, $text['home']) . $delimiter;
 
    if ( is_category() ) {
      $thisCat = get_category(get_query_var('cat'), false);
      if ($thisCat->parent != 0) {
        $cats = get_category_parents($thisCat->parent, TRUE, $delimiter);
        $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
        $cats = str_replace('</a>', '</a>' . $linkAfter, $cats);
        echo $cats;
      }
      echo $before . sprintf($text['category'], single_cat_title('', false)) . $after;
 
    } elseif ( is_search() ) {
      echo $before . sprintf($text['search'], get_search_query()) . $after;
 
    } elseif ( is_day() ) {
      echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
      echo sprintf($link, get_month_link(get_the_time('Y'),get_the_time('m')), get_the_time('F')) . $delimiter;
      echo $before . get_the_time('d') . $after;
 
    } elseif ( is_month() ) {
      echo sprintf($link, get_year_link(get_the_time('Y')), get_the_time('Y')) . $delimiter;
      echo $before . get_the_time('F') . $after;
 
    } elseif ( is_year() ) {
      echo $before . get_the_time('Y') . $after;
 
    } elseif ( is_single() && !is_attachment() ) {
      if ( get_post_type() != 'post' ) {
        $post_type = get_post_type_object(get_post_type());
        $slug = $post_type->rewrite;
        printf($link, $homeLink . '/' . $slug['slug'] . '/', $post_type->labels->singular_name);
        if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after;
      } else {
        $cat = get_the_category(); $cat = $cat[0];
        $cats = get_category_parents($cat, TRUE, $delimiter);
        if ($showCurrent == 0) $cats = preg_replace("#^(.+)$delimiter$#", "$1", $cats);
        $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
        $cats = str_replace('</a>', '</a>' . $linkAfter, $cats);
        echo $cats;
        if ($showCurrent == 1) echo $before . get_the_title() . $after;
      }
 
    } elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() ) {
      $post_type = get_post_type_object(get_post_type());
      echo $before . $post_type->labels->singular_name . $after;
 
    } elseif ( is_attachment() ) {
      $parent = get_post($post->post_parent);
      $cat = get_the_category($parent->ID); $cat = $cat[0];
      $cats = get_category_parents($cat, TRUE, $delimiter);
      $cats = str_replace('<a', $linkBefore . '<a' . $linkAttr, $cats);
      $cats = str_replace('</a>', '</a>' . $linkAfter, $cats);
      echo $cats;
      printf($link, get_permalink($parent), $parent->post_title);
      if ($showCurrent == 1) echo $delimiter . $before . get_the_title() . $after;
 
    } elseif ( is_page() && !$post->post_parent ) {
      /*if ($showCurrent == 1)*/ echo $before . get_the_title() . $after;
 
    } elseif ( is_page() && $post->post_parent ) {
      $parent_id  = $post->post_parent;
      $breadcrumbs = array();
      while ($parent_id) {
        $page = get_page($parent_id);
        $breadcrumbs[] = sprintf($link, get_permalink($page->ID), get_the_title($page->ID));
        $parent_id  = $page->post_parent;
      }
      $breadcrumbs = array_reverse($breadcrumbs);
      for ($i = 0; $i < count($breadcrumbs); $i++) {
        echo $breadcrumbs[$i];
        if ($i != count($breadcrumbs)-1) echo $delimiter;
      }
      /*if ($showCurrent == 1)*/ echo $delimiter . $before . get_the_title() . $after;
 
    } elseif ( is_tag() ) {
      echo $before . sprintf($text['tag'], single_tag_title('', false)) . $after;
 
    } elseif ( is_author() ) {
       global $author;
      $userdata = get_userdata($author);
      echo $before . sprintf($text['author'], $userdata->display_name) . $after;
 
    } elseif ( is_404() ) {
      echo $before . $text['404'] . $after;
    }
 
    if ( get_query_var('paged') ) {
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' <li><span>';
      //echo __('Page','qns') . ' ' . get_query_var('paged');
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo '</span></li>';
    }
 
    echo '</ul></div>';
 
  }
} // end dimox_breadcrumbs()



/* ------------------------------------------------
	WooCommerce Settings
------------------------------------------------ */

/*-----------------------------------------------------------------------------------*/
/* Hook in on activation */
/*-----------------------------------------------------------------------------------*/

global $pagenow;
if ( is_admin() && isset( $_GET['activated'] ) && $pagenow == 'themes.php' ) add_action('init', 'stylemag_woocommerce_image_dimensions', 1);

/*-----------------------------------------------------------------------------------*/
/* Define image sizes / hard crop */
/*-----------------------------------------------------------------------------------*/

function stylemag_woocommerce_image_dimensions() {

// Image sizes
update_option( 'woocommerce_thumbnail_image_width', '270' ); // Image gallery thumbs
update_option( 'woocommerce_thumbnail_image_height', '370' );
update_option( 'woocommerce_single_image_width', '311' ); // Featured product image
update_option( 'woocommerce_single_image_height', '426' );
update_option( 'woocommerce_catalog_image_width', '148' ); // Product category thumbs
update_option( 'woocommerce_catalog_image_height', '203' );

// Hard Crop [0 = false, 1 = true]
update_option( 'woocommerce_thumbnail_image_crop', 1 );
update_option( 'woocommerce_single_image_crop', 1 );
update_option( 'woocommerce_catalog_image_crop', 1 );

}



/* ------------------------------------------------
	Remove width/height dimensions from <img> tags
------------------------------------------------ */

add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );

function remove_thumbnail_dimensions( $html ) {
    $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html );
    return $html;
}


/*-----------------------------------------------------------------------------------
	Remove add to cart button from original position 
-----------------------------------------------------------------------------------*/

remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );



/*-----------------------------------------------------------------------------------
	Remove WooCommerce messages
-----------------------------------------------------------------------------------*/

remove_action( 'woocommerce_before_shop_loop', 'woocommerce_show_messages', 10 );
remove_action( 'woocommerce_before_single_product', 'wc_print_notices', 10 );



/*-----------------------------------------------------------------------------------
	Remove add to cart button from original position 
-----------------------------------------------------------------------------------*/

if ( ! function_exists( 'woocommerce_template_loop_add_to_cart' ) ) {

	function woocommerce_template_loop_add_to_cart_hover() {
		woocommerce_get_template( 'loop/add-to-cart-hover.php' );
	}
	
}



/* ------------------------------------------------
	WooCommerce Breadcrumbs
------------------------------------------------ */

// Disabled default position of WooCommerce breadcrumbs so we can add it where we want
remove_action('woocommerce_before_main_content','woocommerce_breadcrumb', 20, 0);
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 );

if ( ! function_exists( 'woocommerce_breadcrumb' ) ) {

	function woocommerce_breadcrumb( $args = array() ) {

		$defaults = array(
			'delimiter'  => '<li class="separator"><span>/</span></li>',
			'wrap_before'  => '<div class="breadcrumbs-wrapper clearfix"><ul class="breadcrumbs">',
			'wrap_after' => '</ul></div>',
			'before'   => '<li><span>',
			'after'   => '</span></li>',
			'home'    => null
		);

		$args = wp_parse_args( $args, $defaults  );

		woocommerce_get_template( 'shop/breadcrumb.php', $args );
	}
}



/* ------------------------------------------------
	This theme supports WooCommerce, woo!
------------------------------------------------ */

add_theme_support( 'woocommerce' );



/* ------------------------------------------------
	Set Number of Items to be Displayed Per Page
------------------------------------------------ */

if ( $data['shop_per_page'] ) :
	$shop_per_page = $data['shop_per_page'];
else :
	$shop_per_page = '9';
endif;

add_filter('loop_shop_per_page', create_function('$cols', 'return ' . $shop_per_page . ';'));



//add custom post type 'staff'
add_action( 'init', 'add_custom_staff' );

if ( ! function_exists( 'add_custom_staff' ) ) :

	function add_custom_staff() {

		$labels = array(
					'name'			=> __( 'Staff', 'qns' ),
					'singular_name'		=> __( 'Staff', 'qns' ),
					'add_new'		=> __( 'Add New', 'qns' ),
					'add_new_item'		=> __( 'Add New Staff Item', 'qns' ),
					'edit_item'		=> __( 'Edit Staff Item', 'qns' ),
					'new_item'		=> __( 'New Staff Item', 'qns' ),
					'view_item'		=> __( 'View Staff Item', 'qns' ),
					'search_items'		=> __( 'Search Staff Items', 'qns' ),
					'not_found'		=> __( 'No Staff Item found', 'qns' ),
					'not_found_in_trash'	=> __( 'No Staff Items found in Trash', 'qns' ),
					'parent_item_colon'	=> ''
					);

		$args = array(
					'labels'		=> $labels,
					'public'		=> true,
					'publicly_queryable'	=> true,
					'show_ui'		=> true,
					'query_var'		=> true,
					'rewrite'		=> true,
					'capability_type'	=> 'post',
					'hierarchical'		=> false,
					'menu_icon'		=> get_template_directory_uri().'/images/btn-staff.png',
					'menu_position'		=> null,
					'supports'		=> array( 'title', 'editor', 'thumbnail', 'page-attributes', 'excerpt' )
					);

		register_post_type( 'staff', $args );
                //flush_rewrite_rules();
	}

endif;